import 'package:flutter/services.dart';

class NativeUtils {
  static const _platform = MethodChannel('native_utils');

  static Future<void> showToast(String message) async {
    try {
      await _platform.invokeMethod('showNativeToast', {'message': message});
    } on PlatformException catch (e) {
      print("Failed to show native toast: ${e.message}");
    }
  }

  // 设置安全标志（禁止截屏）
  static Future<void> setSecureScreen(bool secure) async {
    try {
      await _platform.invokeMethod('setSecureScreen', {'secure': secure});
    } on PlatformException catch (e) {
      print("Failed to set secure screen: ${e.message}");
    }
  }

  // 检测是否设置了安全标志
  static Future<bool> isSecureScreen() async {
    try {
      return await _platform.invokeMethod('isSecureScreen');
    } on PlatformException catch (e) {
      print("Failed to check secure screen: ${e.message}");
      return false;
    }
  }

  static Future<int?> androidSdkInt() async {
    try {
      return await _platform.invokeMethod('androidSdkInt');
    } on PlatformException catch (e) {
      print("Failed to check secure screen: ${e.message}");
      return null;
    }
  }

  ///压缩图片
  static Future<String> compressImage(String imagePath,
      {int maxWidth = 1024, int maxHeight = 1024, int quality = 80}) async {
    try {
      final String result = await _platform.invokeMethod('compressImage', {
        'imagePath': imagePath,
        'maxWidth': maxWidth,
        'maxHeight': maxHeight,
        'quality': quality,
      });
      return result;
    } on PlatformException catch (e) {
      throw Exception('压缩失败: ${e.message}');
    }
  }

  static Future<bool> checkRootOrJailbreak() async {
    try {
      return await _platform.invokeMethod('checkRootOrJailbreak');
    } on PlatformException catch (e) {
      print("Failed to checkRootOrJailbreak: ${e.message}");
      return false;
    }

  }
}
